﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace GemTowerDefence.GUI
{
  public class Toolbar
  {
    private readonly TileMap _map;
    private readonly Texture2D _texture;
    private readonly SpriteFont _font;

    public Toolbar(TileMap map, Texture2D texture, SpriteFont font)
    {
      _map = map;
      _texture = texture;
      _font = font;
    }

    public void Draw(SpriteBatch spriteBatch, Player player, WaveManager waveManager)
    {
      spriteBatch.Draw(_texture, new Vector2(_map.Width * Game.TextureSize, 0), Color.White);

      var availableGems = string.Format("Gems: {0}", waveManager.AvailableGems);
      var moneyLivesText = string.Format("Gold: {0} Lives: {1}", player.Money, player.Lives);
      var wavesText = string.Format("Wave: {0}/{1}", waveManager.Round, waveManager.NumberOfWaves);
      var monstersText = string.Format("Monsters left: {0}", waveManager.CurrentWave.Enemies.Count);
      var messages = new List<string>
                       {
                         availableGems,
                         moneyLivesText,
                         wavesText,
                         monstersText
                       };

      for (int i = 0; i < messages.Count; i++)
      {
        var text = messages[i];
        var offset = (i + 1) * 20;
        var pos = new Vector2(_map.Width * Game.TextureSize + 5, _map.Height * Game.TextureSize - offset - 10);
        spriteBatch.DrawString(_font, text, pos, Color.White);
      }

      var statePos = new Vector2(_map.Width * Game.TextureSize + 25, _map.Height * Game.TextureSize / 2F);
      switch (waveManager.State)
      {
        case WavesState.Initial:
        case WavesState.PickingGems:
          spriteBatch.DrawString(_font, "Place gems", statePos, Color.Yellow);
          break;
        case WavesState.Running:
          spriteBatch.DrawString(_font, "Round started", statePos, Color.Green);
          break;
      }

    }
  }
}
